<?php
/**
 * Created by PhpStorm.
 * User: clb
 * Date: 2019/1/21
 * Time: 15:02
 */

namespace app\server\model;

use app\server\inter\UploadStrategy;

/**
 * 简单的上传（用于小文件）
 * Class UploadSimple
 * @package app\server\model
 */
class UploadSimple implements UploadStrategy
{
    public function upload(): array
    {
        $info = [];
        foreach ($_FILES as $key => $FILE) {
            $len = file_put_contents(UPLOAD_PATH . $FILE['file_name'], $FILE['file_data'], LOCK_EX);
            $info[][$FILE['file_name']] = $len !== false ? 'success' : 'failed';
        }
        return $info;
    }
}